<template>
  <div class="login-page"  >
<van-nav-bar title="注册账号"  left-arrow/>

   <van-form @submit="onSubmit">
   <van-field
    v-model="username"
    name="username"
    placeholder="请输入账号"
    :rules="[{ required: true, message: '请填写用户名' }]"
  />
   <van-field
    v-model="password"
    type="password"
    name="password"
    placeholder="请输入密码"
    :rules="[{ required: true, message: '请填写密码' }]"
  />
  <div style="margin: 16px;">
    <van-button  block type="info" native-type="submit">注册</van-button>
  </div>
</van-form>
<router-link class="link" to="/login">有账号，去登陆</router-link>
  </div>
</template>

<script>
import { register } from '@/api/user'

export default {
  data () {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    async onSubmit (values) {
      const data = await register(values)
      if (data.status === 400) return this.$toast.fail(data.description)
      this.$router.push('/login')
      this.$toast.success(data.description)
      console.log(data)
    }
  }
}
</script>

<style lang="less" scoped>
.link {
  width: 100% !important;
  color:black;
  font-size: 12px;
  margin-left: 130px;
}
</style>
